<script type="text/javascript">
$(function(){
	var pg = App.demo.feeApplyIndex.ui, pp = pg.params,
		gd = pg.find('.grid');

	gd.mac('grid', {
		cols : [{
			field: 'flowCode', title : '流程编号', width: 160
		},{
			field: 'flowName', title : '流程名称', width: 240
// 		},{
// 			field: 'status', title : '状态', width: 120,
// 			render: function(r){
				
// 			}
		},{
			field: 'sheet', title : '创建人', width: 160,
			render: function(r){
				if (!r.flow || !r.flow.data) {
					return '';
				}
				var s = r.flow.data.sheet;
				if (s) {
					var u = s.user;
					return $('<span class="a"></span>').click(function(){
						alert(u.id);
					}).append(u.name + '(' + u.nick + ')');
				}
			}
		},{
			field: 'id', title : '操作', width: 120,
			render: function(r){
				switch(r.type) {
				case 0:
					return $('<span class="a"></span>').append('撤回');
				case 1:
					return $('<span class="a"></span>').click(function(){
						if (confirm('确定要批准吗？')) {
							$.post(App.ctx + '/fee/apply/audit.do', {
								id: r.flowExeId
							}, function(rs){
								var ro = mac.eval(rs);
								if (ro.success) {
									gd.load();
								}
							});
						}
					}).append('审批');
				case 2:
					return $('<span class="a"></span>').click(function(){
						if (confirm('确定要批准吗？')) {
							$.post(App.ctx + '/fee/apply/audit.do', {
								id: r.flowExeId
							}, function(rs){
								var ro = mac.eval(rs);
								if (ro.success) {
									gd.load();
								}
							});
						}
					}).append('批复');
				}
			}
		}],
		loader: {
			url: App.ctx + '/fee/apply/list.do',
			params: { pageNo: 1, pageSize: 20, flowId: 'feeApply' },
			autoLoad: true
		},
		pagerLength: 20
	});
	
	pg.seek('key').keydown(function(e){
		if (e.keyCode == 13) {
			gd.load({ key: $(this).val() });
		}
	});

	pg.seek('ok').click(function(){
		$.post(App.ctx + '/fee/apply/start.do', {
		}, function(rs){
			var ro = mac.eval(rs), rd = ro.data;
			if (ro.success) {
				var a = rd.code.split('.');
				App.open({
					ctx: a[0],
					action: a[1],
					params: { id: rd.id, data: rd.data }
				}, gd.load);
			}
		});
	});
	
	function adjust(){
		var h = pg.parent().height();
		pg.height(h - 30);
		gd.parent().height(h - 44);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust(); 
});
</script>
<div class="title">
	费用申请
</div>
<div class="head">
	关键字查找：<input type="text" name="key" />
	&nbsp;&nbsp;<button name="ok">新申请</button>
</div>
<div class="body">
	<div class="grid" name="grid"></div>
</div>